<template>
  <div class="user">
    <div class="nav">
      <h1 class="userTitle">个人中心</h1>
      <ul>
        <li>
          <!-- 设置按钮 -->
          <van-icon name="setting-o" @click="listSet = !listSet" />
        </li>
      </ul>
    </div>
    <!-- 个人信息 -->
    <div class="top">
      <img :src="`${loginuser.avatar}`" />
      <div>
        <h1>{{ loginuser.nickname }}</h1>
        <p>id: {{ loginuser.uid }}</p>
        <!-- <p>微信号：{{ loginuser.card_id }}</p> -->
      </div>
    </div>

    <!-- 操作 -->
    <div class="wode">
      <div class="w-title">
        <h3>我的订单</h3>
        <span>
          全部
          <i class="fa fa-angle-right"></i>
        </span>
      </div>
      <div class="wode-bottom">
        <ul v-if="orderStatusNum">
          <li @click="goOrder(0)">
            <van-icon
              color="#FF5A4C"
              name="balance-o"
              :badge="orderStatusNum.unpaid_count"
            />
            <p>待付款</p>
          </li>
          <li @click="goOrder(1)">
            <van-icon
              color="#FF5A4C"
              name="certificate"
              :badge="orderStatusNum.unshipped_count"
            />
            <p>待发货</p>
          </li>
          <li @click="goOrder(2)">
            <van-icon
              color="#FF5A4C"
              name="logistics"
              :badge="orderStatusNum.received_count"
            />
            <p>待收货</p>
          </li>
          <li @click="goOrder(3)">
            <van-icon
              color="#FF5A4C"
              name="chat-o"
              :badge="orderStatusNum.evaluated_count"
            />
            <p>待评价</p>
          </li>
          <li @click="goOrder(4)">
            <van-icon
              color="#FF5A4C"
              name="refund-o"
              :badge="orderStatusNum.refund_count"
            />
            <p>退换/售后</p>
          </li>
        </ul>
      </div>
    </div>

    <!-- 余额 -->
    <div class="balance">
      <ul>
        <li>
          <span>我的余额</span>
          <p>{{ loginuser.now_money }}</p>
        </li>
        <li>
          <span>当前佣金</span>
          <p>{{ loginuser.commissionCount }}</p>
        </li>
        <li>
          <span>优惠券</span>
          <p>0</p>
        </li>
      </ul>
    </div>

    <!-- 我的服务 -->
    <div class="service">
      <div class="service-top">
        <h1>我的服务</h1>
      </div>
      <!-- 宫格 -->
      <van-grid :border="false" :clickable="true">
        <!--  -->
        <van-grid-item text="会员中心">
          <template v-slot:icon>
            <van-icon color="#FF5A4C" name="vip-card-o" />
          </template>
        </van-grid-item>
        <!--  -->
        <van-grid-item text="砍价记录">
          <template v-slot:icon>
            <van-icon color="#FF5A4C" name="bill-o" />
          </template>
        </van-grid-item>
        <!--  -->
        <van-grid-item text="我的推广">
          <template v-slot:icon>
            <van-icon color="#FF5A4C" name="friends-o" />
          </template>
        </van-grid-item>
        <!--  -->
        <van-grid-item text="我的余额">
          <template v-slot:icon>
            <van-icon color="#FF5A4C" name="point-gift-o" />
          </template>
        </van-grid-item>
        <!--  -->
        <van-grid-item text="地址信息">
          <template v-slot:icon>
            <van-icon color="#FF5A4C" name="location-o" />
          </template>
        </van-grid-item>
        <!--  -->
        <van-grid-item text="我的收藏">
          <template v-slot:icon>
            <van-icon color="#FF5A4C" name="star-o" />
          </template>
        </van-grid-item>
        <!--  -->
        <van-grid-item text="优惠券">
          <template v-slot:icon>
            <van-icon color="#FF5A4C" name="bill-o" />
          </template>
        </van-grid-item>
        <!--  -->
        <van-grid-item text="联系客服">
          <template v-slot:icon>
            <van-icon color="#FF5A4C" name="friends-o" />
          </template>
        </van-grid-item>
      </van-grid>
    </div>

    <!-- 侧边栏 -->
    <transition
      enter-active-class="animate__animated animate__fadeInRight"
      leave-active-class="animate__animated animate__fadeOutRight"
    >
      <div v-show="listSet" class="list">
        <!-- 左侧空白 -->
        <div class="leftregion" @click="listSet = !listSet"></div>
        <!-- 右侧内容 -->
        <div class="rightregion">
          <!-- 分组单元格 -->

          <div class="account-top">
            <div class="title-account">管理我的账号</div>
            <div class="img-phone">
              <img :src="userInformation.avatar" >
              <div>绑定手机号:{{userInformation.phone}}</div>
              <div class="current-account">当前账号</div>

            </div>
          </div>

          <van-cell-group>
            <van-cell title="昵称" :value="userInformation.nickname" />
            <van-cell title="ID" :value="userInformation.uid">
              <!-- 使用 right-icon 插槽来自定义右侧图标 -->
              <template #right-icon>
                <i class="fa fa-lock" aria-hidden="true"></i> 
              </template>
            </van-cell>
            <van-cell title="手机号码" :value="userInformation.phone">
              <!-- 使用 right-icon 插槽来自定义右侧图标 -->
              <template #right-icon>
                <i class="fa fa-lock" aria-hidden="true"></i> 
              </template>
            </van-cell>
            <van-cell title="密码" is-link value="点击修改密码" />
          </van-cell-group>

          <div class="btn-change-out">
            <van-button
              class="save-changes"
              type="danger" block round
              native-type="button"
            >保存修改</van-button>

            <van-button
              class="log-out"
              type="danger" plain block round
              native-type="button"
              @click="logout"
              >退出登录</van-button>
          </div>
          
        </div>
      </div>
    </transition>

    <div></div>
  </div>
</template>

<script>
import { mapMutations, mapGetters } from "vuex";
import { Dialog } from "vant";
export default {
  data() {
    return {
      listSet: false, //列表设置标记,默认隐藏
      userInformation:{}, //用户信息
      orderStatusNum: {}, //可获取订单 待付款、待发货数量 等信息
      
    };
  },
  // created() {
  //   // 获取user我的服务里面的值
  //   // http://47.115.51.185/api/menu/user
  //   this.axios('http://47.115.51.185/api/menu/user',{
  //     headers:{
  //       // this代表Vue的实例
  //       'Authori-zation': 'Bearer '+ this.$store.state.token,
  //     }
  //   }).then((result) => {
  //     console.log("获取user我的服务里面的值==>",result);
  //   })
  // },
  created() {
    this.axios.get("http://47.115.51.185/api/user").then((re) => {
      // console.log("User==re=>", re);
      if(re.status==410000){
        this.$router.push('/login');
      }
      this.userInformation=re;
      this.orderStatusNum = re.orderStatusNum;//可获取订单 待付款、待发货数量 等信息
    });
  },

  methods: {
    ...mapMutations(["loginout"]),
    // 退出
    logout() {
      this.loginout();
      Dialog({
        title: "退出登录",
        message: "退出成功",
      }).then(() => {
        this.$router.push("/");
      });
    },
    goOrder(e) {
      this.$router.push("/myOrder/" + e);
    },
  },
  computed: {
    ...mapGetters(["loginuser"]),//用户信息
  },
};
</script>

<style lang="less" scoped>
.user {
  background-color: #f5f5f5;
  height: 93vh;
}
// 顶部 设置按钮 标题
.nav {
  height: 40px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  .userTitle {
    flex: 1;
    text-align: center;
    margin-left: 40px;
  }
  ul {
    li {
      margin-right: 10px;
      i {
        font-size: 22px;
        margin: 3.75px 7.5px;
      }
    }
  }
}
.top {
  display: flex;
  margin: 5px 12px 0px 12px;
  background-color: white;
  padding: 12px;
  border-radius: 12px;
  img {
    width: 75px;
    height: 75px;
    border-radius: 50%;
  }
  div {
    margin-left: 10px;
    margin-top: 12px;
    h1 {
      font-size: 18px;
    }
    p {
      font-size: 18px;
      margin-top: 4px;
      color: #ccc;
    }
  }
}
.wode {
  background-color: white;
  border-radius: 12px;
  margin: 12px;
  padding: 12px;
  .w-title {
    width: 100%;
    height: 20px;
    display: flex;
    justify-content: space-between;
    color: #282828;
    h3 {
      font-size: 18px;
    }
    span {
      color: #666666;
      font-size: 14px;
    }
  }
  .wode-bottom {
    padding: 7.5px 0;
    margin-top: 7.5px;
    padding-bottom: 15px;
    ul {
      display: flex;
      justify-content: space-around;
      li {
        display: flex;
        flex-direction: column;
        i {
          font-size: 30px;
          text-align: center;
          margin-bottom: 7.5px;
        }
        p {
          font-size: 7.5px;
        }
      }
    }
  }
}
// 余额 佣金 优惠券
.balance {
  background-color: white;
  border-radius: 12px;
  margin: 12px;
  padding: 12px;
  color: #282828;
  ul {
    display: flex;
    justify-content: space-around;
    li {
      display: flex;
      flex-direction: column;
      text-align: center;
      span {
        color: #666666;
        font-size: 14px;
        margin-bottom: 7.5px;
      }
      p {
        font-size: 18px;
      }
    }
  }
}
.service {
  background-color: white;
  border-radius: 12px;
  margin: 12px;
  padding: 12px;
  .service-top {
    h1 {
      color: #282828;
      font-size: 18px;
    }
  }
  i {
    font-size: 30px;
  }
}
// 设置=> 侧边栏
.list {
  position: fixed;
  right: 0;
  top: 0;
  z-index: 12;
  width: 100%;
  height: 100%;
  .leftregion {
    position: absolute;
    left: 0;
    top: 0;
    width: 20%;
    height: 100%;
    background-color: rgba(76, 76, 76, 0.5);
  }
  // 右侧内容
  .rightregion {
    position: absolute;
    right: 0;
    top: 0;
    width: 80%;
    height: 100%;
    background-color: #f8f8f8;
    overflow: auto;

    .account-top{
      padding: 10px;
      // 顶部标题
      .title-account{
        font-size: 18px;
        margin-left: 10px;
        line-height: 30px;

      }
      //图片-手机号
      .img-phone{ 
        position: relative;
        font-size: 13px;
        color: #999999;
        display: flex;
        align-items: center;
        border:1px solid #f38d8d;
        border-radius: 5px;
        background-color: rgba(255, 192, 203, 0.2);
        img{
          display: block;
          width: 70px;
          height: 70px;
          border-radius: 50%;
          padding: 10px;
        }
        .current-account{
          font-size: 14px;
          position: absolute;
          right: 0px;
          top: 0px;
          color: red;
          background-color: rgba(255, 192, 203, 0.8);
          border-radius: 0px 5px 0px 5px;
          padding: 3px;
        }
      }
      
    }
    .btn-change-out{
      margin: 15px 5px; 
      .save-changes{
        margin: 5px 0px;
      }
    }
    .fa-lock{
      font-size: 16px;
      line-height: inherit;
      margin-left: 10px;
      color: #969799;
    }
  }
}
</style>
